/**
 * 作者:hanbo
 * 日期:2018/12/69:26
 * 描述:圆形
 */
import {Geometry} from "./Geometry";
import {BoundingBox} from "./BoundingBox";
import {Point} from "./Point";

export class Circle extends Geometry {
    /**
     * 圆形构造器
     * @param center {Point} 圆形中心点
     * @param option {Object} 圆形参数radius:半径,otherPoint:圆上一点,angle:构造三角形夹角,
     */
    constructor(center, option) {
        super("circle", BoundingBox.getCircleBox(center,option));
        this.center=center;
        this.radius=0;
        if(option.hasOwnProperty("radius")){
            this.radius=option.radius;
        }else if(option.hasOwnProperty("otherPoint")){
            this.radius=Point.getDistance(center,option.otherPoint)
        }
        this.array=[];
        this.angle=option.angle;
        this._computeCoor()
    }

    /**
     * 根据圆心和半径自动计算圆外侧线坐标
     * @private
     */
    _computeCoor(){
       const number=360/this.angle;//构造三角形数量
        let currentAngle=0;
        let radian=0;
        let radian_per_degree=Math.PI/180;//一度对应的弧度
        for (let i = 0; i <=number ; i++) {
          this.array.push([this.center.x+Math.cos(radian),this.center+Math.sin(radian)]);
          currentAngle+=this.angle;
          radian=radian_per_degree*currentAngle;
        }
    }
}

